<?php
if (isset($this->popupMessage)) {
    echo $this->popupMessage;
}
$formImage = '<div class="fileupload fileupload-new" data-provides="fileupload">
					<input type="hidden" value="" name="">
					<div class="fileupload-new thumbnail no-image" style="width: 150px; height: 120px;">
						<div class="fileupload-image"><i class="clip-image"></i></div>
					</div>
					<div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 150px; max-height: 120px; line-height: 10px;"></div>
					<div>
						<span class="btn btn-light-grey btn-file"><span class="fileupload-new"><i class="icon-picture"></i> Select image</span><span class="fileupload-exists"><i class="icon-picture"></i> Change</span>
							<input type="file" name="image" id="image">
						</span>
						<a href="#" class="btn fileupload-exists btn-light-grey" data-dismiss="fileupload">
							<i class="icon-remove"></i> Remove
						</a>
					</div>
				</div>';
$introVi = $this->cmsEditor($this->form->introVi,'introVi');
$contentVi = $this->cmsEditor($this->form->contentVi,'contentVi');

$arrInput = array(
	0 => array('label' => 'Tên tin tức', 'input' => $this->form->titleVi , 'requited' => 'YES'),
	1 => array('label' => 'Alias','input' => $this->form->aliasVi,'requited' => 'YES'),
	2 => array('label' => 'Intro','input' => $introVi,'requited' => 'YES'),
	3 => array('label' => 'Content','input' => $contentVi,'requited' => 'YES'),
	4 => array('label' => 'Status','input' => $this->form->status,'requited' => 'YES'),
	5 => array('label' => 'Image','input' => $formImage,'requited','YES'),

);
$arrInput2 = array(
	0 => array('label' => 'Meta Title: ', 'input' => $this->form->metaTitle, 'requited' => 'NO'),
	1 => array('label' => 'Meta Keyword: ', 'input' => $this->form->metaKeyword, 'requited' => 'NO'),
	2 => array('label' => 'Meta Description: ', 'input' => $this->form->metaDescription, 'requited' => 'NO'),		
);

?>
<form role="form" class='form-horizontal' novalidate="novalidate" action='' method="post" enctype="multipart/form-data" onsubmit="return checkForm()">
	<div class="row">
		<div class="col-md-12">
			<!-- start: FORM VALIDATION 1 PANEL -->
			<div class="panel panel-default">
				<div class="panel-heading">
					<i class="icon-external-link-sign"></i>				
				</div>
				<div class="panel-body">
					<div class="tabbable panel-tabs">
						<ul class="nav nav-tabs">
							<li class="active"><a data-toggle="tab" href="#panel_tab_example1">Thông tin chung</a>
							</li>
							<li><a data-toggle="tab" href="#panel_tab_example2">Thuộc tính</a>
							</li>
							<li><a data-toggle="tab" href="#panel_tab_example3">Cấu hình SEO</a>
							</li>							
						</ul>
									
						<div class="tab-content">
							<div class="col-md-12">
								<div id="alert-message"></div>							
					            <?php if (isset($this->error) && $this->error != '') { ?>
								<div class="errorHandler alert alert-danger">
									<i class="icon-remove-sign"></i> Thông báo
									<ul>
				                        <?php
					                        foreach ($this->error as $item) {
					                            echo '<li>' . $item . '</li>';
					                        }
				                        ?>
				                    </ul>
								</div>
								<?php } ?>
								
								<div class="successHandler alert alert-success no-display">
									<i class="icon-ok"></i> Your form validation is successful!
								</div>
							</div>
							<div id="panel_tab_example1" class="tab-pane active">											
								<?php echo $this->partialLoop("_partials/row.phtml", $arrInput); ?>  														
							</div>
							<div id="panel_tab_example2" class="tab-pane">											
								<div class="row">	
									<div class="col-md-12" id='featureDetail'></div>
								</div>
								<div class="row">	
									<div class="col-md-12">
										<div class="form-group">
											<label class="col-sm-2 control-label"></label>	
											<div class="col-sm-9" id='image-attr'></div>											
										</div>
									</div>
								</div> 														
							</div>
							<div id="panel_tab_example3" class="tab-pane">
								<?php echo $this->partialLoop("_partials/row.phtml", $arrInput2); ?> 
							</div>
						</div>
					</div>					
					
					<div class="row">
						<div class="col-md-12">
							<div><hr></div>
						</div>
					</div>
					<div class="row">
						<div class="col-md-9">
							<p>Các trường có dấu <span class="symbol required"></span> là bắt buộc</p>
						</div>
						<div class="col-md-3">
							<a data-style="expand-left" class="btn btn-teal ladda-button" href='<?php echo $this->url(array('module' => 'admin', 'controller' => $this->controllerName, 'action'=>'index')); ?>'>								
								<i class="icon-circle-arrow-left"></i><span class="ladda-label"> Huỷ bỏ </span>
								<span class="ladda-spinner"></span>
							</a>
							<button type="submit" data-style="expand-right" name='btnSave' class="btn btn-teal ladda-button">
								<span class="ladda-label"> Lưu </span>
								<i class="icon-circle-arrow-right"></i>
								<span class="ladda-spinner"></span>
							</button>
						</div>
						
					</div>					
				</div>
			</div>
			<!-- end: FORM VALIDATION 1 PANEL -->
		</div>
	</div>
</form>

<script type="text/javascript">
    $(document).ready(function() {   
    	standardURL('#titleVi', '#aliasVi');
    	standardURL('#titleEn', '#aliasEn');
     
        $('#parentId').change(function() {
            var level = $(this + 'option:selected').attr('data-level');
            if ($(this)[0].selectedIndex === 0) {
                level = 0;
            }

            $('#level').val(parseInt(level) + 1);
        });

        $('.alert .close').live('click', function() {
            $(this).parents('#alert-message').fadeOut();
            $(this).parent('.alert').fadeOut();
        });

        $('#titleVi, #titleEn, #pid').keyup(function() {
            var value = $(this).val();
            if (value != '') {
                $(this).removeClass('required-error');
            }
        });

    });

    function checkForm() {
        var error = true;
        var stError = '';

        if ($('#pid').val() === '') {
            stError += '<li>Chưa nhập mã sản phẩm</li>';
            $('#pid').addClass('required-error');
            error = false;
        } else {
            $('#pid').removeClass('required-error');
        }

        if ($('#titleVi').val() === '') {
            stError += '<li>Chưa nhập tên sản phẩm</li>';
            $('#titleVi').addClass('required-error');
            error = false;
        } else {
            $('#titleVi').removeClass('required-error');
        }
        if ($('#titleEn').val() === '') {
            stError += '<li>Chưa nhập tên sản phẩm (Tiếng anh)</li>';
            $('#titleEn').addClass('required-error');
            error = false;
        } else {
            $('#titleEn').removeClass('required-error');
        }
        //alert($('input[name=itemSelected]:checked').val()); return false;
        /*
        if ($('input[name=itemSelected]').is(":checked") === false) {
            stError += '<li>Chưa chọn hình đại diện</li>';
            $('#itemSelected').addClass('required-error');
            error = false;
        } else {
            $('#itemSelected').removeClass('required-error');
        }
        */
        
        if (!error) {
            $('.errorHandler').remove();
            $('#alert-message').html('<div class="errorHandler alert alert-danger"><button data-dismiss="alert" class="close" type="button">×</button><i class="icon-remove-sign"></i> Thông báo</div>');
            $('.errorHandler').append('<ul>' + stError + '</ul>');
            $('#alert-message').fadeIn();
        }

        return error;
    }
</script>
